package com.imooc.controller;

import com.imooc.pojo.bo.ShopcartBO;
import com.imooc.service.StuService;
import com.imooc.utils.IMOOCJSONResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Api(value = "购物车接口controller",tags = {"购物车接口相关的api"})
@RequestMapping("shopcart")
@RestController
//@ApiIgnore         //隐藏controller
public class ShopcatController {

    @ApiOperation(value = "添加商品到购物车",notes = "添加商品到购物车",httpMethod = "POST")
    @PostMapping("/add")
    public IMOOCJSONResult add(
            @RequestParam String userId,
            @RequestBody ShopcartBO shopcartBO,
            HttpServletRequest request,
            HttpServletResponse response
            ){

        if (StringUtils.isEmpty(userId)){
            return IMOOCJSONResult.errorMsg(null);
        }

        //TODO 前端用户在登录的情况下，添加商品在购物车，会同时在后端同步在购物车到redis缓存

        return IMOOCJSONResult.ok();

    }

    @ApiOperation(value = "从购物车中删除商品",notes = "从购物车中删除商品",httpMethod = "POST")
    @PostMapping("/del")
    public IMOOCJSONResult del(
            @RequestParam String userId,
            @RequestParam String itemSpecId,
            HttpServletRequest request,
            HttpServletResponse response
    ){

        if (StringUtils.isEmpty(userId) || StringUtils.isEmpty(userId)){
            return IMOOCJSONResult.errorMsg(null);
        }

        //TODO 用户在页面删除购物车中的商品数据，如果此时用户已经登录，则需要同步删除后端购物车中的商品

        return IMOOCJSONResult.ok();

    }

}
